<template>
    <slot :controller="controller" :store="store" :model="model" :viewType="viewType" :actions="{ handleSelectChange }">
        <div :class="classNames">
            <AppDrtab 
                v-bind="$attrs" 
                :counterData="store.counterData" 
                :pages="store.pages" 
                :selectItem="store.selectItem" 
                :viewType="viewType" 
                :caption="model.caption" 
                :capPSLanguageRes="model.capPSLanguageRes" 
                :iconClass="model.iconClass" 
                :imgPath="model.imgPath" 
                :codeName="model.codeName" 
                @itemClick="(item:any) => { handleSelectChange(item) }">
            </AppDrtab>
        </div>
    </slot>
</template>
<script setup lang="ts">
// 基于template/src/widgets/{{appEntities}}/{{ctrls@DRTAB}}-drtab/{{spinalCase ctrl.codeName}}-drtab-base.vue.hbs生成
import { AppDrtab } from "@components/widgets/drtab";
import { useProps, useBasic, useAction, useController } from './data-relation-drtab-hook';
import { DrtabActionType, IDrtabAbility, IDrtabStore, IParam } from "@/core/interface";

// 输入参数
const props = defineProps(useProps());

// 基础数据
const { 
    model,
    controlID, 
    getClassNames, 
    useNavParamsBind, 
    useEventBind
} = useBasic(props);

const emit = defineEmits<{
    (event: 'ctrl-action', name: string, action: DrtabActionType, data: IParam[]): void;
    (event: 'ctrl-init', name: string, data: IDrtabAbility): void;
    (event: 'ctrl-destroy', name: string, data: IParam): void;
}>();

const evt = useEventBind(emit);
const classNames = computed(() => {
  return getClassNames(props);
});

const controller = useController(props, evt, { controlID });

const { handleSelectChange } = useAction(controller);

useNavParamsBind(controller, props);

const store: IDrtabStore = controller.getStore();

onMounted(() => {
    controller.ctrlMounted();
});

onUnmounted(() => {
    controller.ctrlDestroy();
})
</script>
